/*********************************************************
*Copyright (c) 2009 Rob Groves. All Rights in Pw
*@des: ios poll
*@name: ios_pool.h
*@author: zhongsx
*@time: 2016-03-28
*********************************************************/

#ifndef __IOS_POOL_H__
#define __IOS_POOL_H__

#include <iostream>
#include <string>
#include <boost/asio.hpp>
#include <boost/bind.hpp>  
#include <boost/shared_ptr.hpp> 
#include <boost/noncopyable.hpp>
#include <boost/thread.hpp>
#include <boost/make_shared.hpp>

//异步ios 保证在程序结束的时候 最后析构
class io_service_pool : public boost::noncopyable
{
public:
	explicit io_service_pool(std::size_t pool_size);
	virtual ~io_service_pool(){
		std::cout << "io_service_pool  delete" << std::endl;
	}

	void start();
	void join();
	void stop();

	boost::asio::io_service& get_io_service();
private:
	typedef boost::shared_ptr<boost::asio::io_service> io_service_sptr;
	typedef boost::shared_ptr<boost::asio::io_service::work> work_sptr;
	typedef boost::shared_ptr<boost::thread> thread_sptr;

	boost::mutex mtx;

	std::vector<io_service_sptr> io_services_;
	std::vector<work_sptr> work_;
	std::vector<thread_sptr> threads_;
	std::size_t next_io_service_;
};

#endif //__IOS_POOL_H__